<template>
    <view class="bg-content">
        <scroll-view scroll-x="true">
            <div class="table table-bordered" style="width: 1000px; text-align: center; background: white;">
                <div class="tr">
                    <div class="td text-center bold">操作</div>
                    <div class="td text-center bold">
                        <div style="width: 100px;">商品图片</div>
                    </div>
                    <div class="td text-center bold">赠品编码</div>
                    <div class="td text-center bold">赠品名称</div>
                    <div class="td text-center bold">数量</div>
                    <div class="td text-center bold">已使用数量</div>
                    <div class="td text-center bold">开始时间</div>
                    <div class="td text-center bold">结束时间</div>
                    <div class="td text-center bold">状态</div>
                </div>
                <div class="tr" v-for="(item, index)  in tbGoodsPresentList" :key="index">
                    <div class="td">
                        <div style="margin-top: 10px; text-decoration: underline;" @click="selectItem(item, index)">
                            选择
                        </div>
                    </div>
                    <div class="td">
                        <myImg :obj="item" :sysFile="{fkId: item.id}" :key="item.id"
                               :customStyle="'pointer-events: none; height: 100px;  width:100px; background-size: cover; background-repeat: no-repeat; background-position: center;'"
                               :defaultUrl="'/pages/sub/sub2-store-platform/static/default-image/goods.jpg'"
                               :imageView="'imageView2/1/w/200/h/200'"
                        ></myImg>
                    </div>
                    <div class="td">{{item.code}}</div>
                    <div class="td">{{item.name}}</div>
                    <div class="td">{{item.quantity}}</div>
                    <div class="td">{{item.usedQuantity}}</div>
                    <div class="td">{{item.startTime}}</div>
                    <div class="td">{{item.endTime}}</div>
                    <div class="td">{{item.statusText}}</div>
                </div>
            </div>
        </scroll-view>

        <div style="padding-top: 50px;" v-if="!tbGoodsPresentList.length">
            <u-empty text="数据为空" mode="data"></u-empty>
        </div>

    </view>
</template>

<script>

    import myImg from '@/components/my-img'
    import {TbStorePresentService} from "@/dev/services/tb-store-present.service";
    import {CommonUtil} from "@/dev/core/utils/common.util";

    export default {
        data() {
            return {
                tbGoodsPresentList: []
            }
        },
        components: {
            myImg
        },
        onShow() {
            this.findTbStorePresentList();
        },
        methods: {
            findTbStorePresentList() {
                const _self = this;
                new TbStorePresentService().findTbStorePresentList({
                    storeId: _self.globalVariable.userInfo.tbStore.id,
                }).then(result => {
                    _self.tbGoodsPresentList = result;
                });
            },
            /***
             * 选择赠品
             * @param item
             * @param index
             */
            selectItem(item, index) {
                if (this.objParams.attrName) {
                    this.objParams.obj[this.objParams.attrName] = item.id;
                    // 获得result0，result1，result2，result3的下标值0,1,2,3...
                    let index = this.objParams.attrName.substring(this.objParams.attrName.length - 1);
                    this.objParams.obj[`tbStorePresent${index}.name`] = item.name;
                }

                console.log(this.objParams);
                CommonUtil.toastNavigateBack();
            }
        }
    }
</script>

<style lang="scss" scoped>
</style>
